Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Char array' - 2 code snippet(s) found

 Sample 1. Remove templatized arguments from a String

String removeTemplatizedArgument(String str){
   String cleanStr = "";
   boolean withinTemplatized=false;   
   int countBlock = 0;
   for(char x: str.toCharArray()){
      if(x == '<'){
         withinTemplatized = true;
         countBlock++;
         continue;
      } else if(x == '>'){
         withinTemplatized = false;
         countBlock--;
         continue;
      } else if(!withinTemplatized && countBlock == 0){
         cleanStr = cleanStr + x;
      }
         
   }
      
   return cleanStr;
}

   Like      Feedback     string  string trim  trim  char  .toCharArray()


 Sample 2. Print duplicate characters in a string / char array without using library

public class CountDuplicates {
   public static void main(String[] args){
      char[] alreadyOccured = new char[10];
      
      char[] charArray = {'b','u','g','g','y','b','r','e','a','d'};
      
      for(int countArray=0;countArray<charArray.length;countArray++){
         boolean charAlreadyOccured = false;
         for(int countAlreadyOccured=0;countAlreadyOccured<alreadyOccured.length;countAlreadyOccured++){
            if(charArray[countArray] == alreadyOccured[countAlreadyOccured]){
               charAlreadyOccured = true;
               break;
            }
         }
         if(charAlreadyOccured){
            System.out.println(charArray[countArray]);
         } else {
            alreadyOccured[countArray] = charArray[countArray];
         }
      }
   }
}

   Like      Feedback     string  char array



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner